﻿using HCQ2_Common;
using HCQ2_Model.ViewModel;
using HCQ2_Model.VLine.InputDto;
using HCQ2_Model.VLine.OutputDto;
using HCQ2_Model.VR.Params;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace HCQ2UI_Logic.DocumentController
{
    public class VLinesManagerController: BaseLogic
    {
        //*********************************1.0 成绩统计**************************************
        #region 1.0 默认首次进入成绩统计界面 + ActionResult DocList()
        /// <summary>
        ///  默认首次进入成绩统计界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult List()
        {
            return View();
        }
        #endregion

        #region 1.1 初始化Table + ActionResult InitTable(ScoreStatistParam model)
        /// <summary>
        ///  初始化Table
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult InitTable(ScoreStatistParam model)
        {
            int total = 0;
            var list = operateContext.bllSession.T_VLinesExperienceDetail.GetScoreStatistList(model, out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 1.2 导出成绩统计 + ActionResult ExportTable(ScoreStatistParam model)
        /// <summary>
        ///  导出成绩统计
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public void ExportTable()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),
                fileCode = RequestHelper.GetStrByName("fileCode"),
                startDate = RequestHelper.GetStrByName("startDate"),
                endDate = RequestHelper.GetStrByName("endDate");
            ScoreStatistParam model = new ScoreStatistParam { user_name = userName, file_code = fileCode, start_date = startDate, end_date = endDate };
            DataTable dt = operateContext.bllSession.T_VLinesExperienceDetail.GetScoreStatistExeclData(model);
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("rowNum", "序号");
            dict.Add("cr_name", "课堂名称");
            dict.Add("file_code", "作品代码");
            dict.Add("file_name", "作品名");
            dict.Add("user_name", "教师姓名");
            dict.Add("folder_code", "关卡代码");
            dict.Add("num", "题号");
            dict.Add("accuracy", "正确率");
            dict.Add("result_ok", "答对人数");
            dict.Add("result_error", "答错人数");
            dict.Add("create_date", "创建日期");
            dict.Add("content", "题目内容");
            dict.Add("answer", "正确答案");
            dict.Add("parse", "题目解析");
            NpoiHelper.DataTableToExeclForNpoi(dt, dict, "成绩统计", "成绩统计", "rowNum", false);
        }
        #endregion

        //*********************************2.0 成绩明细**************************************
        #region 2.0 默认首次进入成绩明细界面 + ActionResult DocList()
        /// <summary>
        ///  默认首次进入成绩明细界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult DetialList()
        {
            return View();
        }
        #endregion

        #region 2.1 初始化Table + ActionResult InitDetialTable(ScoreStatistDetail model)
        /// <summary>
        ///  初始化Table
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult InitDetialTable(ScoreStatistDetail model)
        {
            int total = 0;
            var list = operateContext.bllSession.T_VLinesExperienceDetail.GetScoreStatistDetial(model, out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 2.2 导出成绩明细 + ActionResult {(ScoreStatistParam model)
        /// <summary>
        ///  导出成绩明细
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public void ExportDetialTable()
        {
            string userName = RequestHelper.GetDeStrByName("userName"),
                fileName = RequestHelper.GetDeStrByName("fileName"),
               fileCode = RequestHelper.GetStrByName("fileCode"),
               fileContent = RequestHelper.GetDeStrByName("fileContent"),
               startDate = RequestHelper.GetStrByName("startDate"),
               endDate = RequestHelper.GetStrByName("endDate");
            ScoreStatistDetail model = new ScoreStatistDetail { user_name = userName, file_code = fileCode, start_date = startDate, end_date = endDate,file_name=fileName,content= fileContent };
            DataTable dt = operateContext.bllSession.T_VLinesExperienceDetail.GetScoreStatistDetialExecl(model);
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("rowNum", "序号");
            dict.Add("user_id", "用户id");
            dict.Add("user_name", "用户名");
            dict.Add("file_code", "作品代码");
            dict.Add("file_name", "作品名称");
            dict.Add("teacher_name", "教师姓名");
            dict.Add("cr_name", "课堂名称");
            dict.Add("folder_code", "关卡代码");
            dict.Add("num", "题号");
            dict.Add("status", "得分");
            dict.Add("score", "用户名");
            dict.Add("em_time", "答题时长");
            dict.Add("wm_time", "本题时长");
            dict.Add("create_date", "创建时间");
            dict.Add("content", "题目内容");
            dict.Add("answer", "正确答案");
            dict.Add("sel_result", "选择答案");
            dict.Add("parse", "题目解析");
            NpoiHelper.DataTableToExeclForNpoi(dt, dict, "成绩明细", "成绩明细", "rowNum", false);
        }
        #endregion

        //*********************************3.0 体验记录**************************************
        #region 3.0 默认首次进入体验记录界面 + ActionResult RecordList()
        /// <summary>
        ///  默认首次进入体验记录界面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HCQ2_Common.Attributes.Element]
        [HttpGet]
        public ActionResult RecordList()
        {
            return View();
        }
        #endregion

        #region 3.1 获取体验记录一栏数据 +ActionResult GetRecordList()
        /// <summary>
        ///  获取体验记录一栏数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetRecordList(RecordModel param)
        {
            int total;
            List<RecordResult> list = operateContext.bllSession.T_VLionsRecord.GetRecordList(param,out total);
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 3.2 删除记录 +ActionResult DelExperById(int id)
        /// <summary>
        ///  删除记录
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelExperById(int id)
        {
            if (id <= 0)
                return operateContext.RedirectAjax(1, "需要删除的数据不存在~", "", "");
            int delCount = operateContext.bllSession.T_VLionsRecord.Delete(s => s.er_id == id);
            if (delCount > 0)
                return operateContext.RedirectAjax(0, "数据删除成功~", "", "");
            return operateContext.RedirectAjax(1, "数据删除失败~", "", "");
        }
        #endregion
    }
}